public class Solution14 {
    public String longestCommonPrefix(String[] strs) {
        int c=0;
        if (strs.length==0){
            return "";
        }
        while (true){
            if (c==strs[0].length()){
                return strs[0].substring(0,c);
            }
            char p=strs[0].charAt(c);
            for (int i=1;i<strs.length;i++){
                if (strs[i].length()==c || strs[i].charAt(c)!=p){
                    return strs[0].substring(0,c);
                }
            }
            c++;
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution14().longestCommonPrefix(new String[]{"flower","flow","flight"}));
    }
}
